-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buttons: resistor ladder / analog buttons support #2357
Conversation
- Buttons events source as button property instead of a global one - AnalogPin to read between a certain `analogRead()` range - Refactor `gpio` command, add `gpio 17` to show `analogRead()`
How do you handle the interval borders? In your example: Where do 415 and 724 go? They are in two intervals right now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No comments about the code - it is above my current development level
I tested with WemosD1 Circuit 2: Series Resistor Ladder and also with the actual GOSUND P1 power strip.
Everything works as expected.
I will work next week a Wiki page for Gosund P1 and SP111.
Thank you for this!
Have look at adjustPinRanges method. First the buttons are sorted in ascending order. Then interval borders are computer as average between two "neighbors" values. |
BTW, note of the changes to the config |
analogRead()
rangeTrying to follow defaults here - analog 'press' is digital LOW, default value is HIGH, so no additional cfg entries are needed besides pin, level and changing evt source
gpio
command, addadc
to showanalogRead(pin)
button
commandhttps://gitter.im/tinkerman-cat/espurna?at=5f5d44c8df4af236f902e25d - analog buttons
https://gitter.im/tinkerman-cat/espurna?at=5f60e7f1f969413294e95370 - per-button events source
@alextircovnicu can you check this out?
New config is:
BUTTON_PROVIDER_ANALOG_SUPPORT
BUTTON#_PIN
A0
, Arduino Core macro for the first ADC channel)BUTTON#_PROVIDER
BUTTON_PROVIDER_GENERIC
, for the analog support -BUTTON_PROVIDER_ANALOG
BUTTON#_ANALOG_LEVEL
analogRead()
when the button is pressed(or, at runtime via
btnGPIO0 => 17
,btnProv0 => 2
andbtnLevel0 => 500
respectively)To discover button values, terminal
adc
/adc 17
will show theanalogRead(A0)
result.button
will show button objects that were created.I only tested with 'Circuit 3' from https://github.com/bxparks/AceButton/tree/develop/docs/resistor_ladder as 1k <-> 220, 1k and 4.7k:
adc